package com.yanqu.road.server.cmd.children;

import com.yanqu.road.pb.child.ChildProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.ChildMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_CHILD_RANDOM_NAME, desc = "获取随机名字")
public class ChildRandomNameCmd extends AbstractCommand {

    private int sex;

    private String name = "";

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChildProto.ChildRandomNameReqMsg reqMsg = ChildProto.ChildRandomNameReqMsg.parseFrom(packet.getBytes());
        sex = reqMsg.getSex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        name = ChildMgr.getRandomChildName(sex, player.getLanguage());
    }

    @Override
    public void sendData(GamePlayer player) {
        ChildProto.ChildRandomNameRespMsg.Builder respMsg = ChildProto.ChildRandomNameRespMsg.newBuilder();
        respMsg.setName(name);
        player.sendPacket(Protocol.U_CHILD_RANDOM_NAME, respMsg);
    }
}
